package 算法.练习1;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @author:谢君臣
 * @Date:2021/7/16-19:37
 * @version:1.0
 * @function:
 */
public class hf1 {
    public static void main(String[] args) {

    }
    public float getAvgTravel(int beginAddress, int endAddress ,List<shootCar> list){
        float avg =0;
        HashMap<Integer, Date> hashMap = new HashMap<>();
        List<Long> t = new ArrayList<>();
        boolean flag = false;
        int start = 0, end = 0;
        for (shootCar c : list) {
            if (hashMap.containsKey(c.getCarNum())){
                Date date = hashMap.get(c.getCarNum());
                long l = c.getShootTime().getTime() - date.getTime();
                t.add(l);
                hashMap.remove(c.getCarNum());
            }else {
                hashMap.put(c.getCarNum(),c.getShootTime());
            }
        }
        for (Long aLong : t) {
           avg +=  aLong;
        }
        avg = avg/t.size();
        return avg;
    }
}
